package com.gamewithpurpose.dbinterface;

import static org.junit.Assert.*;

import java.util.List;

import org.junit.Test;

import com.gamewithpurpose.dbinterface.POJO.User;

public class UserDAOTest {
	@Test
	public void testAdd() {
		UserDAO.deleteAll();
		
		UserDAO.addUser("blabla1");
		UserDAO.addUser("blabla2");
		
		List<User> res = UserDAO.list();
		
		assertEquals(res.size(), 2);
	}
	
	@Test
	public void testDelete() {
		UserDAO.deleteAll();
		List<User> res = UserDAO.list();
		assertEquals(res.size(), 0);
		
		UserDAO.addUser("blabla1");
		UserDAO.addUser("blabla2");
		
		res = UserDAO.list();
		
		assertEquals(res.size(), 2);
		
		for (User user : res) {
			UserDAO.delete(user.getid());
		}
		
		res = UserDAO.list();
		
		assertEquals(res.size(), 0);
	}
	
	@Test
	public void testExist() {
		UserDAO.deleteAll();
		
		UserDAO.addUser("blabla1");
		if (!UserDAO.isExist("blabla1"))
			assertTrue(false);
		
		List<User> res = UserDAO.list();
		
		assertEquals(res.size(), 1);
	}
}
